<!-- 地图显示 start-->
<div id="map" class="map" ></div>
<!-- 地图显示 end-->
<script>
    layui.use(['form', 'table', 'util', 'config', 'admin'], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
        var admin = layui.admin;

        var map;
        var ctrl = {};
        var baiduMap = {
            centerLon: 120.384023,
            centerLat: 31.868957,
            zoom: 15,
            city: "无锡"
        };
        var trafficLayer = null;
        //热力图对象
        var heatmapOverlay;
        var mapvLayer = null;
        baiduMap.loadMap = function () {
            // 创建Map实例
            map = new BMap.Map(document.getElementById('map'), {
                enableDeepZoom: false
            });
            //map.centerAndZoom(baiduMap.city, this.zoom);
            map.centerAndZoom(new BMap.Point(this.centerLon, this.centerLat), this.zoom);
            // 初始化地图,设置中心点坐标和地图级别
            map.enableScrollWheelZoom();
            map.enableAutoResize();


            //ctrl = new BMapLib.TrafficControl({showPanel: false});
            //map.addControl(ctrl);
            /* var ctrl = new BMapLib.TrafficControl();
             map.addControl(ctrl);
             ctrl.setAnchor(BMAP_ANCHOR_TOP_LEFT);*/
            /*map.addEventListener("rightclick",function(e){
            console.log(e.point.lng + "," + e.point.lat);
            console.log(map.getZoom());
            });*/
            //map.addEventListener("zoomend", changeLayer);


            //创建点
            addPoint(120.398288, 31.863527,"华宏",'江阴市华宏污水处理厂污水总排');
            addPoint(120.384023, 31.868957,"周西",'江阴市周西污水处理厂污水总排');

            addPoint(120.397959, 31.818504,"周南",'江阴市周南污水处理厂污水总排');

            addPoint(120.40328, 31.875777,"金湾",'江阴市金湾污水处理厂污水总排');

            addPoint(120.389915,31.878713,"周北",'江阴市周北污水处理厂污水总排')

        };
        baiduMap.loadMap();
        var showEditModel = function (data) {
            var admin = layui.admin;
            width = document.body.clientWidth;
            width = width > 380 ? 380 : width;
            admin.popupCenter({
                title: data,
                path: 'components/app/console.html',
                finish: function () {
                    // table.reload('user-table', {});
                },
                area: [width + 'px'],
                shadeClose:true
            });
        };

        function addPoint(x,y,lable,title) {
            var pt = new BMap.Point(x, y);
            var myIcon = new BMap.Icon("assets/images/fac.png", new BMap.Size(40, 40));
            var marker = new BMap.Marker(pt, {icon: myIcon});  // 创建标注
            map.addOverlay(marker);              // 将标注添加到地图中
            marker.addEventListener("click", getAttr);
            function getAttr() {
                var p = marker.getPosition();       //获取marker的位置
                // alert("marker的位置是" + p.lng + "," + p.lat);
                showEditModel(title);
            }
            var label = new BMap.Label(lable,{offset:new BMap.Size(30,-15)});
            marker.setLabel(label);
        }
    });

</script>